package com.sharp.demo.dao.entity;

import com.sharp.authorization.dao.common.entity.AcPermit;
import com.sharp.authorization.dao.common.entity.AcRolePermit;
import com.sharp.authorization.dao.common.entity.AcUser;
import com.sharp.authorization.dao.common.entity.AcUserRole;
import com.sharp.kernel.mybatis.join.anno.JoinCollection;
import com.sharp.kernel.mybatis.join.entity.IJoinRelationship;
import com.sharp.kernel.mybatis.join.entity.JoinRelationship;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Table;
import java.util.List;

/**
 * Title: UserPermitJoin
 * Description: Copyright: Copyright (c) 2019 Company: BHFAE
 *
 * @author Sharp
 * @date 2022/7/8 9:13
 */
@Data
@Table(name = "ac_user")
@EqualsAndHashCode(callSuper = true)
public class UserPermitJoin extends AcUser implements IJoinRelationship {
    @JoinCollection
    private List<AcPermit> permitList;

    @Override
    public List<JoinRelationship> joinRelationship() {
        return buildJoinRelationship(AcUser.class, "id", AcUserRole.class, "userId", JoinRelationship.Type.LEFT_JOIN)
                .add(AcRolePermit.class, "permitId", AcPermit.class, "id", JoinRelationship.Type.LEFT_JOIN)
                .add(AcRolePermit.class, "roleId", AcUserRole.class, "roleId", JoinRelationship.Type.LEFT_JOIN)
                .build();
    }
}
